package fixtures;
import java.io.IOException;

import Library.Books;
import Server.EchoServer;
import client.ClientConsole;
import GUI.GUI_LogIn;
import fit.ActionFixture;

public class BookOrder extends ActionFixture {
	
	 GUI_LogIn cgui;
	 ClientConsole cc;
	 String UserName;
	 String Password;
	 String BookId;
	 EchoServer es;
	 
	 public void server (){
     es=new EchoServer(5555,"root","root");
		try {
			es.listen();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	 
}
	 public void disserver()
	 {
		 
		 try {
			es.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	 }

	public void connect(String ip)
	{
		//cgui=new GUI_LogIn();
		
		cc = new ClientConsole(ip);
		System.out.println(ip);
		Thread t=new Thread(cc);
		t.start();
	}
	
	public void UserName(String s)
	{
	UserName=s;
	}
	public void Password(String s)
	{
	Password=s;
	}
	
	public void login()
	{
		
		String s[]={"login",UserName,Password};
		try {
			cc.client.sendToServer(s);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 

			while(cc.client.flag==0)
				System.out.print("");
			cc.client.flag=0;
			System.out.println("here");
			}
	
	public void disconnect()
	{
	try {
		cc.client.closeConnection();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}	
	}
	
	
	public void logout()
	{
		
		String[] s={"logout",UserName};
		try {
			cc.client.sendToServer(s);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 

			while(cc.client.flag==0)
				System.out.print("");
			cc.client.flag=0;
			System.out.println("here");
		
	}
	
	
	public void bookId(String bId)
	{
	BookId=bId;
	}
	public int order()
	{
	System.out.println("here");
	String s[]={"checkOrderBook",BookId,UserName};
	try {
		cc.client.sendToServer(s);
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
		while(cc.client.flag==0)
			System.out.print("");
	   cc.client.flag=0;
	  //System.out.println("here "+cc.getClient().message);
	 //  System.out.println("here" +cc.getClient().message);
	//  System.out.println(msgNum);
	  return (Integer) cc.client.message;
	
	}
	
	
	
	
	
	
	
	
}

